<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form :inline="true">
            <el-form-item label="商户号：">
              <el-input v-model="tableFrom.merId" placeholder="商户号" class="selWidth" size="small" clearable>
                <el-button slot="append" icon="el-icon-search" size="small" @click="getList(1)" />
              </el-input>
            </el-form-item>
            <el-form-item label="商户名称：">
              <el-input v-model="tableFrom.merName" placeholder="商户名称" class="selWidth" size="small" clearable>
                <el-button slot="append" icon="el-icon-search" size="small" @click="getList(1)" />
              </el-input>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-button size="mini" type="primary" @click="addMerchant({ id: '' })" v-if="checkPermi(['admin:merchant:save'])">开通商户</el-button>
        </div>
      </div>
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini" class="table"
        highlight-current-row>
        <el-table-column prop="id" label="商户号" width="150" />
        <el-table-column prop="merName" label="商户名称" width="150" min-width="100" />
        <el-table-column label="商户账号" min-width="100" prop="account" />
        <el-table-column prop="merFullName" label="商户姓名" min-width="100" />
        <el-table-column prop="merPhone" label="商户手机" min-width="100" />
        <el-table-column prop="merAddress" label="商户地址" min-width="100" />
        <el-table-column prop="merAppId" label="商户AppId" min-width="100" />
        <el-table-column label="创建时间" min-width="130" prop="createTime">
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :page-sizes="[20, 40, 60, 80]" :page-size="tableFrom.limit" :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="handleSizeChange"
          @current-change="pageChange" />
      </div>
    </el-card>
    <el-dialog :title="(editDialogConfig.isCreate === 0 ? `创建商户` : `编辑商户`)" :visible.sync="editDialogConfig.visible"
               destroy-on-close :close-on-click-modal="false" width="50%">
      <edit v-if="editDialogConfig.visible" :is-create="editDialogConfig.isCreate" :edit-data="editDialogConfig.data"
            @hideEditDialog="hideEditDialog"/>
    </el-dialog>
  </div>
</template>
  
<script>
import { merchantListApi } from '@/api/merchant'
import { checkPermi } from "@/utils/permission"; // 权限判断函数
import edit from './edit'
export default {
  name: 'AccountsCapital',
  components: { edit },
  data() {
    return {
      timeVal: [],
      tableData: {
        data: [],
        total: 0
      },
      listLoading: true,
      tableFrom: {
        type: '',
        page: 1,
        limit: 20
      },
      userTableFrom: {
        page: 1,
        limit: 10,
        dateLimit: ''
      },
      editDialogConfig: {
        visible: false,
        isCreate: 0, // 0=创建，1=编辑
        data: {}
      },
      fromList: this.$constants.fromList,
      options: []
    }
  },
  mounted() {
    // this.getTypes()
    this.getList()
  },
  methods: {
    checkPermi,
    // 列表
    getList(num) {
      this.listLoading = true
      this.tableFrom.page = num ? num : this.tableFrom.page;
      merchantListApi(this.tableFrom).then(res => {
        this.tableData.data = res.list
        this.tableData.total = res.total
        this.listLoading = false
      }).catch((res) => {
        this.listLoading = false
      })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    },
    getTypes() {
      billTypeApi().then(res => {
        this.options = res.data
        localStorage.setItem('CashKey', JSON.stringify(res.data))
      }).catch((res) => {
        this.$message.error(res.message)
      })
    },
    hideEditDialog() {
      setTimeout(() => {
        this.editDialogConfig.visible = false
        this.getList()
      }, 200)
    },
    addMerchant() {
      this.editDialogConfig.isCreate = 0
      this.editDialogConfig.data = {}
      this.editDialogConfig.visible = true
    },
  }
}
</script>
  
<style scoped lang="scss">
.dashboard-workplace {
  &-header {
    &-avatar {
      width: 64px;
      height: 64px;
      border-radius: 50%;
      margin-right: 16px;
      font-weight: 600;
    }

    &-tip {
      width: 82%;
      display: inline-block;
      vertical-align: middle;
      margin-top: -12px;

      &-title {
        font-size: 13px;
        color: #000000;
        margin-bottom: 12px;
      }

      &-desc {
        width: 100%;

        &-sp {
          width: 32%;
          color: #17233D;
          font-size: 13px;
          display: inline-block;
          line-height: 25px;
        }
      }
    }

    &-extra {
      .ivu-col {
        p {
          text-align: right;
        }

        p:first-child {
          span:first-child {
            margin-right: 4px;
          }

          span:last-child {
            color: #808695;
          }
        }

        p:last-child {
          font-size: 22px;
        }
      }
    }
  }
}

.selWidth {
  width: 300px;
}

.color_red {
  color: #F5222D;
}

.color_green {
  color: #7ABE5C;
}
</style>
  